package cn.doitedu.hbase.day01;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

public class GetDemo {


    public static void main(String[] args) throws Exception {

        Connection connection = null;
        Table table = null;
        try {
            connection = ConnectionUtils.getConnection();

            //将数据写入到Hbase中
            //获取一个表
            table = connection.getTable(TableName.valueOf("tb_users2"));

            //如果不指定get的查询条件，就是将全部列组族数据都查询处理
            //最好指定查询的列族，并且指定的列的标识符
            Get get = new Get(Bytes.toBytes("016400"));
            get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
            get.addColumn(Bytes.toBytes("f2"), Bytes.toBytes("city"));
            Result result = table.get(get);
            byte[] v1 = result.getValue(Bytes.toBytes("f1"), Bytes.toBytes("name"));
            if (v1 != null) {
                String name = new String(v1);
                System.out.println(name);
            }
            byte[] v2 = result.getValue(Bytes.toBytes("f2"), Bytes.toBytes("city"));
            if (v2 != null) {
                String province = new String(v2);
                System.out.println(province);
            }
            //scala

            //删除用delete
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (table != null)
                table.close();
            if (connection != null)
                connection.close();
        }






    }
}
